package com.example.replacebooks.common;

import lombok.Data;

@Data
public class Result {

    private static final String SUCCESS = "0";
    private static final String ERROR = "-1";
    //返回给前端的
    private String code;  //返回的状态 （成功还是失败）
    private String msg;   //后台报错信息返回到这个字段里
    private Object data;  //返回的数据

    //不带数据到前端 成功
    public static Result success(){
        Result result =new Result();
        result.setCode(SUCCESS);
        return result;
    }

    //带数据到前端 成功
    public static Result success(Object data){
        Result result =new Result();
        result.setCode(SUCCESS);
        result.setData(data);
        return result;
    }

    // 失败
    public static Result error(String msg){
        Result result =new Result();
        result.setCode(ERROR);
        result.setMsg(msg);
        return result;
    }
}
